﻿using System;
using System.Data;
using System.IO;
using System.Windows.Forms;
using HRM.HRMServiceProxy;
using WeifenLuo.WinFormsUI.Docking;

namespace HRM
{
    public partial class frmEmployeeLCInvalidSpecialList : DockContent
    {
        DateTime _date = DateTime.Now;
        EmployeeClient wcfEmployee;
        BranchClient wcfBranch;
        DepartmentClient wcfDepartment;
        RoleRightInfo listRole;
        MainServiceClient wcfMain;
        int _itemCount = 0;
        int _pageSize = UIParamater.pageSize;
        int _totalPage = 0;
        int _currPage = 0;
        string _OrderBy = "";
        string _OrderDirection = "";
        int _employeeID = 0;
        int _type = 6;
        int branch_ID = 0;
        int department_ID = 0;
        int _Total = 0;
        int _day = 0;
        public frmEmployeeLCInvalidSpecialList()
        {
            InitializeComponent();
            LoadLanguage();

            wcfEmployee = Service.Employee();
            wcfBranch = Service.Branch();
            wcfDepartment = Service.Department();
            wcfMain = Service.MainService();
            UISetting.LoadTreeView3(ref tvBranch);
            listRole = UIParamater.Quyen_HoSoCanBo;

            if (!listRole.Update)
            {
                this.btnEdit.Image = global::HRM.Properties.Resources.app;
                this.btnEdit.Tag = "xem";
            }
            BuildVoucherGrid();
            if (cboMonth.Text.Length > 0)
                _day = Convert.ToInt32(cboMonth.Text);
            LoadData();
        }

        private void LoadLanguage()
        {
            this.TabText = this.Text = UpdateUI.GetString(this.Tag.ToString());
            UpdateUI.Load_ToolStrip(ref toolStrip2);
            UpdateUI.Load_ContextMenuStrip(ref mnuPopUp);
        }

        private void BuildVoucherGrid()
        {
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_ID", "Mã chính", "", 1, false, true);
            UISetting.AddColumn(ref dgvEmployeeList, "RowNumber", UpdateUI.GetString("stt"), "C", 50, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_Code", UpdateUI.GetString("maso"), "", 120, false, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_FullName", UpdateUI.GetString("hovaten"), "", 150, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_CardNo", "", "C", 80, false, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_Sex", "", "C", 75, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_DateOfBirth", UpdateUI.GetString("ngaysinh"), "R", 105, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_PlaceOfBirth", UpdateUI.GetString("noisinh"), "", 140, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_Address", UpdateUI.GetString("diachi"), "", 150, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_Phone", UpdateUI.GetString("dienthoai"), "", 120, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "MaritalStatus_Name", UpdateUI.GetString("tinhtranghonnhan"), "", 150, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Religion_Name", UpdateUI.GetString("tongiao"), "", 120, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Ethnic_Name", UpdateUI.GetString("dantoc"), "", 120, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_IDCardNo", UpdateUI.GetString("CMTND"), "", 120, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_IDCardIssueDate", UpdateUI.GetString("ngaycap"), "", 120, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_IDCardIssueAuthority", UpdateUI.GetString("noicap"), "", 150, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_BankAccountNo", UpdateUI.GetString("sotaikhoan"), "", 120, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_BankName", UpdateUI.GetString("nganhang"), "", 120, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "Employee_BankName", UpdateUI.GetString("nganhang"), "", 120, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "BRANCH_NAME", UpdateUI.GetString("chinhanh"), "", 200, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "DEPARTMENT_NAME", UpdateUI.GetString("phongban"), "", 200, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "LC_BeginDate", UpdateUI.GetString("ngaybatdau"), "", 120, true, true);
            UISetting.AddColumn(ref dgvEmployeeList, "LC_FinishDate", UpdateUI.GetString("ngayketthuc"), "", 120, true, true);


        }

        private void PageIndex()
        {
            _totalPage = _itemCount % _pageSize > 0 ? (_itemCount / _pageSize) + 1 : (_itemCount / _pageSize);
            if (_totalPage == 0)
                lblPageIndex.Text = "0" + "/" + _totalPage.ToString();
            else
                lblPageIndex.Text = (_currPage + 1).ToString() + "/" + _totalPage.ToString();
        }

        private void LoadData()
        {
            if (cboMonth.Text.Length > 0)
                _day = Convert.ToInt32(cboMonth.Text);
            DataSet ds = wcfEmployee.Employee_GetLabourContract(out _itemCount, out _Total, _day, _date, _type, _OrderBy, _OrderDirection, _currPage, _pageSize, branch_ID, department_ID);
            PageIndex();
            dgvEmployeeList.Rows.Clear();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dgvEmployeeList.Rows.Insert(i, 1);
                dgvEmployeeList.Columns["Employee_FullName"].Frozen = true;
                dgvEmployeeList.Rows[i].Cells["RowNumber"].Value = ds.Tables[0].Rows[i]["RowNumber"].ToString();
                dgvEmployeeList.Rows[i].Cells["Employee_ID"].Value = ds.Tables[0].Rows[i]["Employee_ID"].ToString();
                dgvEmployeeList.Rows[i].Cells["Employee_Code"].Value = ds.Tables[0].Rows[i]["Employee_Code"].ToString();
                dgvEmployeeList.Rows[i].Cells["Employee_CardNo"].Value = ds.Tables[0].Rows[i]["Employee_Code"].ToString();
                dgvEmployeeList.Rows[i].Cells["Employee_FullName"].Value = ds.Tables[0].Rows[i]["Employee_FullName"].ToString();
                if (ds.Tables[0].Rows[i]["Employee_DateOfBirth"] != DBNull.Value)
                    dgvEmployeeList.Rows[i].Cells["Employee_DateOfBirth"].Value = Convert.ToDateTime(ds.Tables[0].Rows[i]["Employee_DateOfBirth"]).ToString("dd/MM/yyyy");
                else
                    dgvEmployeeList.Rows[i].Cells["Employee_DateOfBirth"].Value = "";
                dgvEmployeeList.Rows[i].Cells["Employee_PlaceOfBirth"].Value = ds.Tables[0].Rows[i]["Employee_PlaceOfBirth"].ToString();
                dgvEmployeeList.Rows[i].Cells["Employee_Address"].Value = ds.Tables[0].Rows[i]["Employee_Address"].ToString();
                dgvEmployeeList.Rows[i].Cells["Employee_Phone"].Value = ds.Tables[0].Rows[i]["Employee_Phone"].ToString();

                dgvEmployeeList.Rows[i].Cells["Employee_Sex"].Value = ds.Tables[0].Rows[i]["Employee_Sex"].ToString();
                dgvEmployeeList.Rows[i].Cells["MaritalStatus_Name"].Value = ds.Tables[0].Rows[i]["MaritalStatus_Name"].ToString();
                dgvEmployeeList.Rows[i].Cells["Religion_Name"].Value = ds.Tables[0].Rows[i]["Religion_Name"].ToString();
                dgvEmployeeList.Rows[i].Cells["Ethnic_Name"].Value = ds.Tables[0].Rows[i]["Ethnic_Name"].ToString();
                dgvEmployeeList.Rows[i].Cells["Employee_IDCardNo"].Value = ds.Tables[0].Rows[i]["Employee_IDCardNo"].ToString();
                dgvEmployeeList.Rows[i].Cells["Employee_IDCardIssueDate"].Value
                    = ds.Tables[0].Rows[i]["Employee_IDCardIssueDate"] == DBNull.Value ? ""
                    : Convert.ToDateTime(ds.Tables[0].Rows[i]["Employee_IDCardIssueDate"]).ToString("dd/MM/yyyy");
                dgvEmployeeList.Rows[i].Cells["Employee_IDCardIssueAuthority"].Value = ds.Tables[0].Rows[i]["Employee_IDCardIssueAuthority"].ToString();
                dgvEmployeeList.Rows[i].Cells["Employee_BankAccountNo"].Value = ds.Tables[0].Rows[i]["Employee_BankAccountNo"].ToString();
                dgvEmployeeList.Rows[i].Cells["Employee_BankName"].Value = ds.Tables[0].Rows[i]["Employee_BankName"].ToString();
                dgvEmployeeList.Rows[i].Cells["BRANCH_NAME"].Value = ds.Tables[0].Rows[i]["BRANCH_NAME"].ToString();
                dgvEmployeeList.Rows[i].Cells["DEPARTMENT_NAME"].Value = ds.Tables[0].Rows[i]["DEPARTMENT_NAME"].ToString();
                dgvEmployeeList.Rows[i].Cells["LC_BeginDate"].Value
                    = ds.Tables[0].Rows[i]["LC_BeginDate"] == DBNull.Value ? ""
                    : Convert.ToDateTime(ds.Tables[0].Rows[i]["LC_BeginDate"]).ToString("dd/MM/yyyy");
                dgvEmployeeList.Rows[i].Cells["LC_FinishDate"].Value
                    = ds.Tables[0].Rows[i]["LC_FinishDate"] == DBNull.Value ? ""
                    : Convert.ToDateTime(ds.Tables[0].Rows[i]["LC_FinishDate"]).ToString("dd/MM/yyyy");
            }
        }



        private void btnEmployee_Contract_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedRows.Count > 0)
            {
                _employeeID = Convert.ToInt32(dgvEmployeeList.SelectedRows[0].Cells["Employee_ID"].Value);
                Form f = new frmLabourContractInfo(0, _employeeID, listRole);
                if (f.ShowDialog(this) == DialogResult.OK)
                {
                    LoadData();
                }
            }
            else
            {
                MessageBox.Show(UpdateUI.GetString("chuachonnhanvien"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void dgvEmployeeList_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
                btnEdit_Click(null, null);
        }

        private void btnEditPopUp_Click(object sender, EventArgs e)
        {
            btnEdit_Click(null, null);
        }

        private void btnDeletePopUp_Click(object sender, EventArgs e)
        {
            btnDel_Click(null, null);
        }

        private void mnuSoanHDLD_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedRows.Count > 0)
            {
                if (listRole.Update || listRole.View)
                {
                    _employeeID = Convert.ToInt32(dgvEmployeeList.CurrentRow.Cells["Employee_ID"].Value);
                    frmPreviewReport f = new frmPreviewReport("ContractTemplate", new string[] { _employeeID.ToString() });
                    f.Show(this);
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void mnuQDNghiHuongBHXH_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedRows.Count > 0)
            {
                if (listRole.Update || listRole.View)
                {
                    _employeeID = Convert.ToInt32(dgvEmployeeList.CurrentRow.Cells["Employee_ID"].Value);
                    frmPreviewReport f = new frmPreviewReport("QDNghiHuongBHXH", new string[] { _employeeID.ToString() });
                    f.Show(DockPanel);
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }


        private void mnuIncreaseSalary_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedRows.Count > 0)
            {
                if (listRole.Update || listRole.View)
                {
                    _employeeID = Convert.ToInt32(dgvEmployeeList.CurrentRow.Cells["Employee_ID"].Value);
                    frmPositionDetailsInfo f = new frmPositionDetailsInfo(0, _employeeID, listRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                        LoadData();
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void mnuFurlough_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedRows.Count > 0)
            {
                if (listRole.Update || listRole.View)
                {
                    _employeeID = Convert.ToInt32(dgvEmployeeList.CurrentRow.Cells["Employee_ID"].Value);
                    frmLeaveWorkInfo f = new frmLeaveWorkInfo(0, _employeeID, listRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                        LoadData();
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void mnuOffered_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedRows.Count > 0)
            {
                if (listRole.Update || listRole.View)
                {
                    _employeeID = Convert.ToInt32(dgvEmployeeList.SelectedRows[0].Cells["Employee_ID"].Value);
                    RoleRightInfo _lRole = UIParamater.Quyen_DeNghiTroCap;

                    frmOfferedInfo f = new frmOfferedInfo(0, _lRole, _employeeID);
                    if (f.ShowDialog(this) == DialogResult.OK)
                        LoadData();
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void txtKeyWord_KeyUp(object sender, KeyEventArgs e)
        {

        }

        private void btnFind_Click(object sender, EventArgs e)
        {

        }

        private void mnuDeclaration_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedRows.Count > 0)
            {
                _employeeID = Convert.ToInt32(dgvEmployeeList.SelectedRows[0].Cells["Employee_ID"].Value);
                if (listRole.Update || listRole.View)
                {
                    frmPreviewReport f = new frmPreviewReport("ToKhai", new string[] { _employeeID.ToString() });
                    f.Show(this);
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void mnuQDTangLuong_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedRows.Count > 0)
            {
                if (listRole.Update || listRole.View)
                {
                    _employeeID = Convert.ToInt32(dgvEmployeeList.SelectedRows[0].Cells["Employee_ID"].Value);
                    frmPreviewReport f = new frmPreviewReport("QDTangLuong", new string[] { _employeeID.ToString() });
                    f.Show(this);
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void mnuComment_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedRows.Count > 0)
            {
                if (listRole.Update || listRole.View)
                {
                    _employeeID = Convert.ToInt32(dgvEmployeeList.SelectedRows[0].Cells["Employee_ID"].Value);
                    RoleRightInfo _lRole = UIParamater.Quyen_HoSoCanBo;

                    frmCommentInfo f = new frmCommentInfo(0, _employeeID, _lRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                        LoadData();
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void mnuCurriculumVitae_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedRows.Count > 0)
            {
                _employeeID = Convert.ToInt32(dgvEmployeeList.SelectedRows[0].Cells["Employee_ID"].Value);
                if (listRole.Update || listRole.View)
                {
                    frmPreviewReport f = new frmPreviewReport("SYLL", new string[] { _employeeID.ToString() });
                    f.Show(this);
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void tvBranch_AfterSelect(object sender, TreeViewEventArgs e)
        {
            DataTable dt = new DataTable();
            if (e.Node.Level == 0)
            {
                if (Program.isAdmin || Program.isViewAll)
                    branch_ID = 0;
                else
                    branch_ID = Program.intBranchID;
                department_ID = 0;
                LoadData();
            }
            else if (e.Node.Level == 1)
            {
                branch_ID = Convert.ToInt32(e.Node.Tag);
                department_ID = 0;
                _currPage = 0;
                LoadData();
            }
            else if (e.Node.Level >= 2)
            {
                department_ID = Convert.ToInt32(e.Node.Tag);
                branch_ID = Convert.ToInt32(e.Node.Parent.Tag);
                _currPage = 0;
                LoadData();
            }
        }


        private void btnWarning_Click(object sender, EventArgs e)
        {
            _currPage = 0; ;
            LoadData();
        }

        private void cboMonth_SelectedIndexChanged(object sender, EventArgs e)
        {
            _currPage = 0;
            LoadData();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (dgvEmployeeList.SelectedRows.Count > 0)
            {
                if (listRole.Update || listRole.View)
                {
                    _employeeID = Convert.ToInt32(dgvEmployeeList.SelectedRows[0].Cells["Employee_ID"].Value);
                    Form f = new frmEmployeeInfo(_employeeID, 0, 0, UIParamater.Employee_LCInvalid, listRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                    {
                        LoadData();
                    }
                }
                else
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxem"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void btnDel_Click(object sender, EventArgs e)
        {

            if (dgvEmployeeList.SelectedRows.Count > 0)
            {
                if (!listRole.Delete)
                {
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxoa"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                _employeeID = Convert.ToInt32(dgvEmployeeList.SelectedRows[0].Cells["Employee_ID"].Value);
                if (wcfEmployee.Employee_Using(_employeeID) == 0)
                {
                    if (MessageBox.Show(UpdateUI.GetString("bancochacchanxoa"), UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        if (wcfEmployee.Employee_Delete(_employeeID))
                        {
                            Program.taskbarNotifier.Show(UIParamater.TitleProject, UpdateUI.GetString("xoathanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                            _currPage = 0;
                            LoadData();
                        }
                        else
                        {
                            MessageBox.Show(UpdateUI.GetString("xoakhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
                else
                {
                    MessageBox.Show(UpdateUI.GetString("dasudung"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

            }
        }

        private void btnExcel_Click(object sender, EventArgs e)
        {
            string _fileName = "";
            string branchName = "";
            string departmentName = "";
            _fileName = "tmpHHHD.xls";
            if (branch_ID > 0)
            {
                branchName = wcfBranch.Branch_GetInfo(branch_ID).Name;
            }

            if (department_ID > 0)
            {
                departmentName = wcfDepartment.Department_GetInfo(department_ID).Name;
            }
            try
            {
                DataSet ds = wcfEmployee.Employee_GetLabourContract(out _itemCount, out _Total, _day, _date, _type, _OrderBy, _OrderDirection, _currPage, _pageSize, branch_ID, department_ID);
                if (ds.Tables.Count > 0)
                {
                    ds.Tables[0].Columns.Remove("Employee_ID");
                    ds.Tables[0].Columns.Remove("EMPLOYEE_RELIGIONID");
                    ds.Tables[0].Columns.Remove("EMPLOYEE_ETHLICID");
                    ds.Tables[0].Columns.Remove("EMPLOYEE_CARDNO");
                    ds.Tables[0].Columns.Remove("LC_EmployeeID");
                    ds.Tables[0].Columns.Remove("Branch_ID");
                    ds.Tables[0].Columns.Remove("EMPLOYEE_SIBOOKNO");
                    ds.Tables[0].Columns.Remove("Branch_Name");
                    ds.Tables[0].Columns["Rownumber"].Caption = "STT";
                    ds.Tables[0].Columns["Employee_Code"].Caption = "Mã nhân viên";
                    ds.Tables[0].Columns["Employee_FullName"].Caption = "Họ và tên";
                    ds.Tables[0].Columns["Employee_DateofBirth"].Caption = "Ngày sinh";
                    ds.Tables[0].Columns["Employee_PlaceOfBirth"].Caption = "Nơi sinh";
                    ds.Tables[0].Columns["Employee_Sex"].Caption = "Giới tính";
                    ds.Tables[0].Columns["Employee_Address"].Caption = "Địa chỉ";
                    ds.Tables[0].Columns["Employee_Phone"].Caption = "Điện thoại";
                    ds.Tables[0].Columns["Standard_Name"].Caption = "Trình độ";
                    ds.Tables[0].Columns["National_Name"].Caption = "Quốc tịch";
                    ds.Tables[0].Columns["Ethnic_Name"].Caption = "Dân tộc";
                    ds.Tables[0].Columns["Religion_Name"].Caption = "Tôn giáo";
                    ds.Tables[0].Columns["MaritalStatus_Name"].Caption = "TTHN";
                    ds.Tables[0].Columns["Employee_IDCardNo"].Caption = "CMTND";
                    ds.Tables[0].Columns["Employee_IDCardIssueDate"].Caption = "Ngày cấp CMT";
                    ds.Tables[0].Columns["Employee_IDCardIssueAuthority"].Caption = "Nơi cấp CMT";
                    ds.Tables[0].Columns["Employee_BankAccountNo"].Caption = "Số tài khoản";
                    ds.Tables[0].Columns["Employee_BankName"].Caption = "Ngân hàng";
                    ds.Tables[0].Columns["LC_BeginDate"].Caption = "Ngày bắt đầu HĐ";
                    ds.Tables[0].Columns["LC_FinishDate"].Caption = "Ngày hết hạn HĐ";
                    ds.Tables[0].Columns["Employee_StartDate"].Caption = "Ngày vào Cty";
                    ds.Tables[0].Columns["Employee_EndDate"].Caption = "Ngày thôi việc";
                    //ds.Tables[0].Columns["Branch_Name"].Caption = "Chi nhánh";
                    ds.Tables[0].Columns["Department_Name"].Caption = "Phòng ban";
                    ds.Tables[0].Columns["Position_Name"].Caption = "Chức vụ";
                    ds.Tables[0].Columns["ContractType_Name"].Caption = "Loại hợp đồng";

                    ReadExcelFile.exportToExcelForEmployeeList("DANH SÁCH NHÂN VIÊN ĐẶC BIỆT HẾT HẠN HỢP ĐỒNG", branchName, departmentName, ds, Path.GetTempPath() + "\\" + _fileName);

                    try
                    {
                        System.Diagnostics.Process.Start(Path.GetTempPath() + "\\" + _fileName);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Không mở được File \n" + Path.GetTempPath() + "\\" + _fileName, "Thông báo");
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("File " + Path.GetTempPath() + "\\" + _fileName + " đang được mở bằng một ứng dụng khác.\nHãy chọn file khác!", "Thông báo");
            }
        }

        private void frmEmployeeLCInvalidSpecialList_FormClosing(object sender, FormClosingEventArgs e)
        {
            wcfEmployee.Close();
            wcfBranch.Close();
            wcfDepartment.Close();
            wcfMain.Close();
        }

        private void btnFisrt_Click(object sender, EventArgs e)
        {

            _currPage = 0;
            LoadData();
        }

        private void btnNext_Click(object sender, EventArgs e)
        {

            if (_totalPage > 0 && _currPage < _totalPage - 1)
                _currPage++;
            LoadData();
        }

        private void btnLast_Click(object sender, EventArgs e)
        {
            if (_totalPage != 0)
                _currPage = _totalPage - 1;
            LoadData();
        }

        private void btnPrevious_Click(object sender, EventArgs e)
        {
            if (_currPage > 0)
                _currPage--;
            LoadData();
        }

        private void frmEmployeeLCInvalidSpecialList_KeyUp(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Escape:
                    this.Dispose();
                    this.Close();
                    break;
                case Keys.F3:
                    btnEdit_Click(null, null);
                    break;
            }
        }

        private void dgvEmployeeList_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {

                if (dgvEmployeeList.Rows.Count > 0)
                {

                    btnNewPopUp.Enabled = true;

                    mnuDeclaration.Enabled = true;
                    btnEditPopUp.Enabled = true;
                    btnDeletePopUp.Enabled = true;
                    mnuQDNghiHuongBHXH.Enabled = true;
                    mnuIncreaseSalary.Enabled = true;
                    mnuFurlough.Enabled = true;
                    mnuOffered.Enabled = true;
                    mnuComment.Enabled = true;
                }
                else
                {
                    btnNewPopUp.Enabled = true;

                    mnuDeclaration.Enabled = false;
                    btnEditPopUp.Enabled = false;
                    btnDeletePopUp.Enabled = false;
                    mnuQDNghiHuongBHXH.Enabled = false;
                    mnuIncreaseSalary.Enabled = false;
                    mnuFurlough.Enabled = false;
                    mnuOffered.Enabled = false;
                    mnuComment.Enabled = false; ;
                }
            }
        }

        private void frmEmployeeLCInvalidSpecialList_Activated(object sender, EventArgs e)
        {
            LoadLanguage();
            if (dgvEmployeeList.Columns.Count > 0)
            {
                dgvEmployeeList.Columns["RowNumber"].HeaderText = UpdateUI.GetString("stt");
                dgvEmployeeList.Columns["Employee_Code"].HeaderText = UpdateUI.GetString("maso");
                dgvEmployeeList.Columns["Employee_CardNo"].HeaderText = UpdateUI.GetString("sothe");
                dgvEmployeeList.Columns["Employee_FullName"].HeaderText = UpdateUI.GetString("hovaten");
                dgvEmployeeList.Columns["Employee_DateOfBirth"].HeaderText = UpdateUI.GetString("ngaysinh");
                dgvEmployeeList.Columns["Employee_PlaceOfBirth"].HeaderText = UpdateUI.GetString("noisinh");
                dgvEmployeeList.Columns["Employee_Address"].HeaderText = UpdateUI.GetString("diachi");
                dgvEmployeeList.Columns["Employee_Phone"].HeaderText = UpdateUI.GetString("dienthoai");
                dgvEmployeeList.Columns["Employee_Sex"].HeaderText = UpdateUI.GetString("gioitinh");
                dgvEmployeeList.Columns["MaritalStatus_Name"].HeaderText = UpdateUI.GetString("tinhtranghonnhan");
                dgvEmployeeList.Columns["Religion_Name"].HeaderText = UpdateUI.GetString("tongiao");
                dgvEmployeeList.Columns["Ethnic_Name"].HeaderText = UpdateUI.GetString("dantoc");
                dgvEmployeeList.Columns["Employee_IDCardNo"].HeaderText = UpdateUI.GetString("CMTND");
                dgvEmployeeList.Columns["Employee_IDCardIssueDate"].HeaderText = UpdateUI.GetString("ngaycap");
                dgvEmployeeList.Columns["Employee_IDCardIssueAuthority"].HeaderText = UpdateUI.GetString("noicap");
                dgvEmployeeList.Columns["Employee_BankAccountNo"].HeaderText = UpdateUI.GetString("sotaikhoan");
                dgvEmployeeList.Columns["Employee_BankName"].HeaderText = UpdateUI.GetString("nganhang");
                dgvEmployeeList.Columns["LC_BeginDate"].HeaderText = "Ngày bắt đầu HĐ";
                dgvEmployeeList.Columns["LC_FinishDate"].HeaderText = "Ngày kết thúc HĐ";
            }
        }

        private void dgvEmployeeList_CellDoubleClick_1(object sender, DataGridViewCellEventArgs e)
        {
            if (dgvEmployeeList.SelectedRows.Count > 0)
                btnEdit_Click(null, null);
        }
    }
}

